package lifeOfAFish.scenegraph.test;


import lifeOfAFish.test.JoglTemplate;
import java.io.File;

import javax.media.opengl.*;
//import javax.media.opengl.GLAutoDrawable;

import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import lifeOfAFish.scenegraph.*;
import lifeOfAFish.scenegraph.geom.*;

import lifeOfAFish.fishModels.amago.*;

public class test_amago extends JoglTemplate {
	
	// scenegraph nodes
	sgNode root = new sgNode();
	Amago amago = new Amago();
	sgLight light = null;
	
	sgTransform rot = new sgTransform();
	sgTransform trans = new sgTransform();
	
	
	float theta = 0.0f;
	float theta2 = 0.0f;
	float step = 1.0f;
	
	
	public static void main (String[] args){
		test_amago template = new test_amago();
		template.setVisible(true);
		
	}

	public void init(GLAutoDrawable drawable)
	{
		super.init(drawable);
		
		// get gl object
		GL gl = drawable.getGL();
		sgGlobals.gl = gl;
		com.loader.glWrapper.gl = gl;
		
		// enable depth testing
		gl.glEnable(GL.GL_DEPTH_TEST);
		gl.glDepthRange(0.0, 1000.0);
		
		// enable lighting
		gl.glEnable(GL.GL_LIGHTING);
		gl.glShadeModel(GL.GL_SMOOTH);
		gl.glEnable(GL.GL_TEXTURE_2D);
		
		gl.glEnable(GL.GL_TEXTURE_2D);
		gl.glEnable(GL.GL_COLOR_MATERIAL);
		gl.glEnable(GL.GL_BLEND);
		gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE_MINUS_SRC_ALPHA);
		gl.glLightModeli(GL.GL_LIGHT_MODEL_COLOR_CONTROL, GL.GL_SEPARATE_SPECULAR_COLOR);
		
		// construct the scenegraph tree.
//		float s = 0.045f;
		float s = 1000.0f;
		light = sgLightFactory.newLight();
		root.addChild(light);
		
		float[] lpos = {2.0f, 2.0f, 2.0f, 1.0f};
		light.setPosition(lpos);
		
		rot.addChild(trans);
		trans.translate(2.0f, 1.0f, 0.0f);
		trans.addChild(light);
		
		amago.init();
		sgTransform scale = new sgTransform();
		scale.scale(100.0f, 100.0f, 100.0f);
		scale.addChild(amago.getNode());
		root.addChild(scale);
	
	}
	
	
	/*
	 * overwritten version of display
	 */
	public void display(GLAutoDrawable drawable)
	{
		// get the gl object
		GL gl = drawable.getGL();
		// set the erasing color (black)
		gl.glClearColor(0f, 0f, 0f, 0f);
		// clear screen with the defined erasing color and depth buffer
		
		gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
		gl.glPushMatrix();
		applyMouseTranslation(gl);
		applyMouseRotation(gl);
		
		theta += step;
		rot.rotate(theta, 0.0f, 1.0f, 0.0f);
		
		// fire the traversal
		root.traverse();
		
		// delay for a while
//		double time = System.currentTimeMillis();
//		while (System.currentTimeMillis() - time < 80);
		
		
		// load an object using the mesh loader
		gl.glPopMatrix();
	}
	
	
}
